export const subValueIn = function (startValue, endValue, minLimit, maxLimit) {
  const bigValue =
    endValue === null || endValue > maxLimit ? maxLimit : endValue;
  const smallValue =
    startValue == null || startValue < minLimit ? minLimit : startValue;
  return bigValue - smallValue;
};

export const parseDateLimit = function (time) {
  const timeDate = new Date(time);
  const year = timeDate.getFullYear();
  const month = timeDate.getMonth();
  const date = timeDate.getDate();
  // const hour = timeDate.getHours();
  // const minute = timeDate.getMinutes();
  // const second = timeDate.getSeconds();
  const start = new Date(year, month, date);
  const startMills = start.getTime();
  var endMills = startMills;
  switch (time.length) {
    case 4: {
      endMills = new Date(year + 1, 0, 1).getTime() - 1;
      break;
    }
    case 6:
    case 7: {
      if (month === 11) {
        endMills = new Date(year + 1, 0, 1).getTime();
        break;
      }
      endMills = new Date(year, month + 1, 1).getTime();
      break;
    }
    case 9:
    case 10: {
      endMills = startMills + 24 * 60 * 60 * 1000;
      break;
    }
    // case 13: {
    //   endMills = startMills + 60 * 60 * 1000;
    //   break;
    // }
    // case 16: {
    //   endMills = startMills + 60 * 1000;
    //   break;
    // }
    // default: {
    //   endMills = startMills + 1000;
    // }
  }
  const end = new Date(endMills - 1);
  return { start, end };
};

export const getLastMonthString = function () {
  const now = new Date();
  const year = now.getFullYear();
  const month = now.getMonth();
  var value = "";
  if (month > 9) {
    value = `${year}-${month}`;
  } else if (month > 0) {
    value = `${year}-0${month}`;
  } else {
    value = `${year - 1}-12`;
  }
  return value;
};

export const getMonthDayCount = function (month) {
  const array = month.split("-");
  const date = new Date(parseInt(array[0]), parseInt(array[1]), 0);
  return date.getDate();
};
export const getLastYearString = function () {
  const now = new Date();
  const year = now.getFullYear();
  return year - 1 + "";
};
export const getYearDayCount = function (year) {
  const v = parseInt(year);
  return v % 4 === 0 ? 366 : 365;
};
